package com.major.dawn.leetCode.string;

import java.util.Calendar;

import static java.lang.Character.getNumericValue;

/**
 * 回文串，回文结构的判断
 */
public class PalindromeStringLongest {

//    确定字符由大写字母和小写字母组成，ASCII 是一种 7 位字符集，包含了所有字母。
    int[] hashEntry = new int[128];

//    字符有多少对重复
    int cal;

    public int longestPalindrome(String s) {
        char[] toCharArray = s.toCharArray();
        if (toCharArray.length ==1 ) {
            return 1;
        }
        for (int i = 0; i < toCharArray.length; i++) {
            int value =toCharArray[i];
            int entryVal = hashEntry[value];
            if (entryVal == 1) {
                cal++;
                hashEntry[value] = 0;
            }
            if (entryVal == 0) {
                hashEntry[value] = 1;
            }
        }

        if (cal > 0) {
            if (toCharArray.length == cal * 2) {
                return cal * 2;
            }
            return cal * 2 + 1;
        }
        return 1;
    }





    public static void main(String[] args) {

        PalindromeStringLongest palindromeString = new PalindromeStringLongest();
        int palindrome = palindromeString.longestPalindrome("aaaAaaaa");
        System.out.println(palindrome);

    }

}
